﻿using Quartz;
using Quartz.Impl;

namespace Batman.Jianbei.Forum.Jobs
{
    public class ChatroomRegister
    {
        public static void SchedulerShow()
        {
            var factory = new StdSchedulerFactory();
            IScheduler scheduler = factory.GetScheduler().Result;

            // 判断用户是否还在房间
            var memberIsInRoomCheckJob = JobBuilder.Create<MemberIsInRoomCheckJob>().Build();
            // 每两分钟执行一次
            var memberIsInRoomCheckJobTrigger = TriggerBuilder.Create().WithSimpleSchedule(t => t.WithIntervalInMinutes(2).RepeatForever()).Build();
            scheduler.ScheduleJob(memberIsInRoomCheckJob, memberIsInRoomCheckJobTrigger);

            // 判断房间成员是否都已退出
            var roomMeberCheckJob = JobBuilder.Create<RoomMemberCheckJob>().Build();
            // 每1分钟执行一次
            var roomMeberCheckJobTrigger = TriggerBuilder.Create().WithSimpleSchedule(t => t.WithIntervalInMinutes(1).RepeatForever()).Build();
            scheduler.ScheduleJob(roomMeberCheckJob, roomMeberCheckJobTrigger);

            // 每2秒执行一次
            var _roomCounterJob = JobBuilder.Create<RoomCounterJob>().Build();
            var roomCounterTrigger = TriggerBuilder.Create().WithSimpleSchedule(t => t.WithIntervalInSeconds(2).RepeatForever()).Build();
            scheduler.ScheduleJob(_roomCounterJob, roomCounterTrigger);

            scheduler.Start();
        }
    }
}
